package com.centling.smartSealForPhone.widget.galleryview;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.utils.GlideApp;

/**
 *
 * @author fionera
 * @date 16-5-5
 */
public class GlideLoader
        implements MediaLoader {

    private String url;

    public GlideLoader(String url) {
        this.url = url;
    }

    @Override
    public boolean isImage() {
        return true;
    }

    @Override
    public void loadMedia(Context context, final ImageView imageView, final SuccessCallback callback) {
        GlideApp.with(context).load(url).placeholder(R.drawable.iv_default).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(Drawable resource,
                                        Transition<? super Drawable> transition) {
                imageView.setImageDrawable(resource);
                callback.onSuccess(resource);
            }
        });
    }

    @Override
    public void loadThumbnail(Context context, final ImageView thumbnailView, final SuccessCallback callback) {
        GlideApp.with(context).load(url).override(100,100).centerCrop().into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(Drawable resource,
                                        Transition<? super Drawable> transition) {
                thumbnailView.setImageDrawable(resource);
                callback.onSuccess(resource);
            }
        });
    }
}
